package fitdroid.helpers;

import fitdroid.helpers.numberformat;
import android.location.Location;

public class MyGpsListener {

	/**
	 * @param args
	 */
	
	private Location oldlocation = null;
	private Location currentlocation = null;
	private double currentspeed=0;
	private double currentcalorie=0;
	private double currenttime=0;
	private double currentdistance = 0;
	private double currentaltitude = 0;
	


	private double maxdistance;
	private double maxspeed;
	private double maxcalorie;
	private double maxtime;
	
	private timehelper timehelp;
	private numberformat numberhelper;
	
	private double runnerweight=70; // Just as Standart 
	
	
	public MyGpsListener()
	{
		getRunnerweight();
	}
	
	public MyGpsListener(String maxdistance,String maxspeed,String maxcalorie,String maxtime )
	{			
		this.maxdistance=Double.valueOf(maxdistance);
		this.maxspeed=Double.valueOf(maxspeed);
		this.maxcalorie=Double.valueOf(maxcalorie);
		this.maxtime=timehelp.converttimeseconds(maxtime);
		
		getRunnerweight();
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	
	public double[] getvalues ()
	{
		return new double[]{numberhelper.round2commas(currentdistance),
							numberhelper.round2commas(currentspeed),
							numberhelper.round2commas(currentcalorie),
							numberhelper.round2commas(currentaltitude)};

	}
	
	public void updatevalues(Location loc)
	{
		this.currentdistance+=calccurrentdistance(loc);
		this.currentspeed=loc.getSpeed();
		this.currentaltitude=loc.getAltitude();
		this.currentcalorie=calccurrentcalorie();
	}
	
	public double calccurrentdistance(Location newloc)
	{
		if (oldlocation == null) 
		{
			oldlocation=newloc;
			return 0;
		} 
		else 
		{
			double temp= (oldlocation.distanceTo(newloc) / 1000) ;
			oldlocation=newloc;
			return temp;
		}
	}
	
	public double calccurrentcalorie()
	{
		return runnerweight*currentdistance;
	}
	
	//TODO get the Runners weight from DB
	public void getRunnerweight()
	{
		
	}
}
